/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package evaluation.ged;

import evaluation.Vertex;
import java.util.regex.Pattern;
import util.StringSimWrapper;

/**
 *
 * @author phong
 */
public class VertexSubstitution extends EditOperation {
    
    Vertex oldV, newV;

    public VertexSubstitution(Vertex v1, Vertex v2) {
        this.oldV = v1;
        this.newV = v2;
    }
    
    public Vertex getOldVertex() {
        return this.oldV;
    }
    
    public Vertex getNewVertex() {
        return this.newV;
    }
    
    @Override
    public double getCost() {
        if (oldV.getType() == Vertex.TYPE_LABEL || oldV.getType() == Vertex.TYPE_REF)
            return 0;
        else {
            if (oldV.getType() == Vertex.TYPE_OPT)
                return 10000 * (oldV.getLabel().equals(newV.getLabel()) ? 0 : 1);
            else 
                //return 1 - StringSimWrapper.calSim(oldV.getLabel(), newV.getLabel());            
                return (oldV.getLabel().equals(newV.getLabel()) ? 0 : 1);
        }
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof VertexSubstitution) {
            VertexSubstitution that = (VertexSubstitution)o;
            return that.newV.equals(this.newV) && that.oldV.equals(this.oldV);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return this.newV.hashCode() * 31 + this.oldV.hashCode() * 17 + "vertexsubstitution".hashCode();
    }
    
    @Override
    public String toString() {
        return "Sub(" + this.oldV.toString() + "," + this.newV.toString() + ") with cost " + this.getCost();
    }
}
